{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "063ef699-f946-4f93-b6e7-f9f2768a4b7b",
   "metadata": {},
   "source": [
    "# 向量水果店\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c558f090-cdf5-4d2e-a570-f29c3891d967",
   "metadata": {},
   "source": [
    "## 1. 基于向量的表示方法\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f37c4318-b6d3-4666-b80e-f344a8dedca7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "380"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 * 70 + 3 * 80"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6d992b21-4697-49b5-95fd-34cc667c8db5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d6ae15f9-ac27-4110-a869-8959ae2e596e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac1a3a3e-ea5b-4b3e-bd5c-404dd68a3ce1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1258e958-13a0-4d17-873e-0ace4d909afe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "140"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(2) * np.array(70)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99a7a5ed-a1ee-4973-a491-96112d3ca4cf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ab853d1-f55b-40b9-8919-e0eff486f1d0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "b0c0b7bc-7441-4b8a-91ce-27b0b72bba8a",
   "metadata": {},
   "source": [
    "价格向量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0d0cbe9f-32b4-40a9-ae00-f26d0985d4cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 3])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = np.array([2, 3])\n",
    "p"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f245b7b-6fad-41c9-bcbc-7369b98e2db2",
   "metadata": {},
   "source": [
    "<br>\n",
    "\n",
    "采购数量向量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f81e9358-dbd8-498d-bfb5-176d9d579eaf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([70, 80])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([70, 80])\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "38c47109-2e24-4746-8513-e7bda2217fde",
   "metadata": {},
   "source": [
    "$$\n",
    "p \\cdot a = (p_1, p_2,\\dots, p_n) \\cdot (a_1, a_2,\\dots, a_n)\n",
    "=\\sum_{i=1}^n p_{i}* a_i\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a8659c40-8f91-4cfb-9ada-9426b77c6e5e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "380"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p @ a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51c34ba5-0b93-472e-9b8a-119576121845",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "af2c3d36-0a50-4fc6-830d-630dbb9eadee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "140"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = np.array([2])\n",
    "a = np.array([70])\n",
    "\n",
    "p @ a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "612a5093-994b-44a6-bac7-d2982b3ce5aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "380"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = np.array([2, 3])\n",
    "a = np.array([70, 80])\n",
    "\n",
    "p @ a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "a04fa70c-e525-4ed1-9057-cbe9a8ad224e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "740"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = np.array([2, 3, 4])\n",
    "a = np.array([70, 80, 90])\n",
    "\n",
    "p @ a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44209050-6b2f-4aee-aea7-34a3400ce7e2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9891b6f7-6a4d-4759-8033-0092ce2336d0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([140, 240])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = np.array([2, 3])\n",
    "a = np.array([70, 80])\n",
    "\n",
    "p * a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "8eb6cca3-3791-404c-b172-2d0559902cb5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "380"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(p * a).sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1f415bb-9fdb-455a-9c64-a5a445149f2c",
   "metadata": {},
   "source": [
    "## 2. 基于矩阵的表示方法\n",
    "\n",
    "如果客户这个订单是实际要分3个批次采购：\n",
    "* 第1个批次： 苹果20，香蕉40\n",
    "* 第2个批次： 苹果35，香蕉15\n",
    "* 第3个批次： 苹果15，香蕉25\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e299d7b7-ec1d-4636-b386-ae8c2b844bb9",
   "metadata": {},
   "source": [
    "<br>\n",
    "采购批次矩阵："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "0433a165-bee3-4741-b3b1-8acaf27bb9c6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[20, 40],\n",
       "       [35, 15],\n",
       "       [15, 25]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = np.array([[20, 40], [35, 15], [15, 25]]) \n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b722b70f-26a3-4622-bfcc-aabe5c97bd76",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "c2612f9e-89e6-4445-a2f3-bf16d2166ab1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([160, 115, 105])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = np.array([2, 3])\n",
    "\n",
    "A @ p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1d3425e-6ee9-4d26-aef4-772d738c84ba",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "20dd6445-d915-479e-a433-4d24562bf9e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([160, 115, 105])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p @ A.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fca58324-9cb3-4468-ac52-4cff2f83d6b9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b731d667-9e5a-4d07-bdda-f01e337fb3be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "380"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(A @ p).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00b9911f-90d5-435c-b7b7-ed6c6bb2650a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "484b2bc7-e98a-49f3-a561-ff2af6b472e5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "380"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(p @ A.T).sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "601d24a4-3dd3-47c4-be07-269b7e98212c",
   "metadata": {},
   "source": [
    "## 价格方案\n",
    "\n",
    "在实际执行时，价格上是有两个等级折扣：\n",
    "* 第一等级$2\\%$的折扣\n",
    "* 第二等级$3\\%$的折扣。\n",
    "\n",
    "$$\n",
    "实际价格 = (1 - 折扣) \\cdot  价格 \n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4441a6c-336b-4edd-baaa-b5bb117ed8e2",
   "metadata": {},
   "source": [
    "三种折扣方案：不打折，打折$2\\%$，打折$3\\%$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "67c157a2-df27-452d-b24e-561c49d2b1be",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7654461f-d984-4591-9706-14a6fe35bd90",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "6bfea334-f17e-4504-8ad2-d873a6efc37a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.  , 0.98, 0.97])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = 1 - np.array([0, 0.02, 0.03])\n",
    "d"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a5b9054-434c-45e7-b426-33baf74e21ea",
   "metadata": {},
   "source": [
    "<br>\n",
    "\n",
    "三种折扣方案针对苹果和香蕉的折扣方案"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "54ee967c-9b01-4728-9547-a1fcdfd3e0c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2.  , 3.  ],\n",
       "       [1.96, 2.94],\n",
       "       [1.94, 2.91]])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "P = np.outer(d, p)\n",
    "P"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a50a579-73e9-4c15-9a17-65a829644204",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "4d81c052-21f6-446f-8ad8-d9c239816673",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([380. , 372.4, 368.6])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array([70, 80])\n",
    "\n",
    "P @ a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "bbecafec-4515-4a56-98d3-c90aecd7760f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([380. , 372.4, 368.6])"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a @ P.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd6daf12-ba82-4f3e-be6a-37c5dd74ec58",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "133a77dc-c99c-48b0-b6e4-7784c491c8a8",
   "metadata": {},
   "source": [
    "<br>\n",
    "\n",
    "如果针对该订单3批采购，分别执行这个三个价格方案"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a749a704-e4b9-48a1-89e2-f05fc193435f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "6fb2d52b-13cf-4572-87b3-6533494af127",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[160.  , 156.8 , 155.2 ],\n",
       "       [115.  , 112.7 , 111.55],\n",
       "       [105.  , 102.9 , 101.85]])"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A @ P.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "5d705e79-b40d-4f20-bfeb-aee8c3cf6729",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[160.  , 115.  , 105.  ],\n",
       "       [156.8 , 112.7 , 102.9 ],\n",
       "       [155.2 , 111.55, 101.85]])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = P @ A.T\n",
    "X"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86f3c972-7cbe-4b22-8a81-232a37e0586f",
   "metadata": {},
   "source": [
    "<br>\n",
    "\n",
    "三个价格方案的总计收入："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "3369ff39-09eb-41b9-aa8c-fd848b3d1922",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([380. , 372.4, 368.6])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X.sum(axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa56f8ea-47ff-48df-afb2-548eb3e13055",
   "metadata": {},
   "source": [
    "<br>\n",
    "\n",
    "矩阵对角线是什么含义？（第4个价格方案）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "c979e732-0bb5-495b-911d-22f3744059fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([160.  , 112.7 , 101.85])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.diag(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "2ae930c6-4193-401a-84e2-53ec87a46a37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "374.54999999999995"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.diag(X).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a171c54-2fd0-41b0-a9bf-69dfe4919c3d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac58cbc7-badf-4887-8482-3a607239cf98",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "6d2ae0eb-245a-4bbc-8a96-54144afb6ed6",
   "metadata": {},
   "source": [
    "# 总结：信息“维度”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "95114690-b92a-4001-815f-e78930592595",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a5d70f33-c4a2-4d64-ac33-abedbad92729",
   "metadata": {},
   "source": [
    "### “点”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d29a704b-ed00-4bfd-a929-389edc6b5e6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "140"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 * 70"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "39381b50-0456-40ae-a05d-ee6cf8c2bcbe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "140"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(2) * np.array(70)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a85da68-546c-45ba-87b8-d6d90210d71c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "3f7a7088-091a-41c7-9666-8e238579a369",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "140"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = np.array([2])\n",
    "a = np.array([70])\n",
    "\n",
    "p @ a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5b997dc-d1ad-4998-9550-6f3e9d3c522d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "49fcc063-f60f-42fb-9d2b-05603fdd3d4b",
   "metadata": {},
   "source": [
    "### “线”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "811c1f2d-a6d3-4ad5-9cdf-3eebc3cb230d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "380"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = np.array([2, 3])\n",
    "a = np.array([70, 80])\n",
    "\n",
    "p @ a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aa2c4a2e-568d-4b07-b583-cd8ff2c3586f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "b2d1e157-d38f-4d4c-af66-1941fb564aca",
   "metadata": {},
   "source": [
    "### “面”\n",
    "在向量$a$的基础上（各水果采购数量），增加“采购批次”信息（维度）\n",
    "\n",
    "由1维信息（向量）变为2维信息（矩阵）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6a6f42fb-1ed7-4a19-95ff-eb2aac649b26",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[20, 40],\n",
       "       [35, 15],\n",
       "       [15, 25]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = np.array([[20, 40], [35, 15], [15, 25]]) \n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "6f35e053-8417-4d8d-9b5e-e401686bc606",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([160, 115, 105])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = np.array([2, 3])\n",
    "\n",
    "A @ p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1862ba1d-bf66-4ed1-9974-4f5ddbbd712f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([160, 115, 105])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p @ A.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60232e36-4f67-4503-84f5-4ae34e280c10",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "ff0b5a4e-945a-4db7-a518-c0da17823ed1",
   "metadata": {},
   "source": [
    "在采购价格向量$p$的基础上，增加的“价格方案”信息“维度”\n",
    "\n",
    "与价格有关的信息由1维信息（向量）变为2维信息（矩阵）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "11017ffe-fb3b-41f6-ba72-f5f766b06712",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2.  , 3.  ],\n",
       "       [1.96, 2.94],\n",
       "       [1.94, 2.91]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = 1 - np.array([0, 0.02, 0.03])\n",
    "P = np.outer(d, p)\n",
    "P"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "74c5838e-a8d4-4b2f-b19a-cfa4eb2ac89c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([380. , 372.4, 368.6])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "P @ a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "d412dffe-198f-4df1-b599-9d52a1c3e9c3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([380. , 372.4, 368.6])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a @ P.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "746ef431-6962-4dec-b150-0dcdea4d0946",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "280c55c9-fc6a-4135-b233-e12401dfc5f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[160.  , 115.  , 105.  ],\n",
       "       [156.8 , 112.7 , 102.9 ],\n",
       "       [155.2 , 111.55, 101.85]])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "P @ A.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "2e711d3a-be94-4175-b9ed-d18be2cb676f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[160.  , 156.8 , 155.2 ],\n",
       "       [115.  , 112.7 , 111.55],\n",
       "       [105.  , 102.9 , 101.85]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A @ P.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6240f005-03a5-495c-9a30-881f1bf19853",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "5aa21054-0166-4c91-8350-9d0eb3f182c2",
   "metadata": {},
   "source": [
    "下面的计算就是没任何意义，因为“批次”信息和“价格”信息无直接“相互作用”，<br>\n",
    "只能间接通过“采购价格”与“采购数量”信息维度相互作用，发生关系。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "e630a91b-87b2-41da-af2d-98824109be75",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2.  , 3.  ],\n",
       "       [1.96, 2.94],\n",
       "       [1.94, 2.91]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "P"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "acc40569-9fd5-4293-a044-5c72884c1f6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[137.7 , 206.55],\n",
       "       [157.9 , 236.85]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A.T @ P"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "8414f1a4-7200-4c23-8ee3-950c6028840b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[137.7 , 157.9 ],\n",
       "       [206.55, 236.85]])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "P.T @ A"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
